package com.tang.zk.client.zookeeper;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;

/**
 * @Classname ZkClient
 * @Description [ TODO ]
 * @Author Tang
 * @Date 2020/12/19 16:51
 * @Created by ASUS
 */
public class ZkClient {

    public static void main(String[] args) throws Exception{
        // 默认的watch
        ZooKeeper client = new ZooKeeper("localhost:2181", 3000, new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                System.out.println("客户端连接成功..." + event);
            }
        });

        Stat stat = new Stat();
        byte[] clientData = client.getData("/luban", new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                System.out.println("原生方式只会触发一次事件：" + event);
            }
        }, stat);

        System.out.println("获取到的数据--->" + new String(clientData));

        System.in.read();
    }

}